package rwt.server.handlers.web;

import rwt.server.*;
import rwt.server.RailroadMessages.LocoSpdMsg;
import rwt.server.WebMessages.SetTrainSpeed;
import rwt.server.core.*;
import rwt.server.railroad.*;

public class SetTrainSpeedHandler extends MessageHandler<SetTrainSpeed>
{
	@Override
	public void handle(SetTrainSpeed message, IConnection source) throws Exception
	{
		Train t = RailServer.getTrainManager().getTrainById(message.trainId);
		int slot = t.getVirtualSlotNum();
		LocoSpdMsg msg = new LocoSpdMsg(slot, message.speed);
		
		RailroadSystem system = t.isEmergency() ? RailServer.getRailroadServer() : RailServer.getController();
		system.write(msg);
	}
}
